package com.r_z.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.r_z.entity.FiscalExpenditure;
import com.r_z.service.FiscalExpenditureService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 财务支出
 * @author :yimeng
 * @date :2023/5/30  8:51
 * @description:some description
 */
@RestController
@CrossOrigin
public class FiscalExpenditureController {
    @Resource
    FiscalExpenditureService fiscalExpenditureService;

    /**
     * 根据主键ID查询
     * @param fExpenditureId
     * @return
     */
    @RequestMapping("selectAllFiscalExpenditure")
    public List<FiscalExpenditure> selectAllFiscalExpenditure(String fExpenditureId){
        return fiscalExpenditureService.selectAllFiscalExpenditure(fExpenditureId);
    }

    /**
     * 根据条件查询总行数后进行分页
     * @param page 当前页
     * @param limit 每页显示数
     * @param fiscalExpenditure
     * @return
     */
    @RequestMapping("LimitFiscalExpenditure")
    public Map LimitFiscalExpenditure(int page,int limit,FiscalExpenditure fiscalExpenditure){
        //查询加分页
        List<FiscalExpenditure> fiscalExpenditureList = fiscalExpenditureService.LimitFiscalExpenditure(page,limit,fiscalExpenditure);
        //查行数
        int count = fiscalExpenditureService.countFiscalExpenditure(fiscalExpenditure);
        System.out.println("行数"+count);
        //创建Map对象
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",fiscalExpenditureList);
        //返回值
        return map;
    }

    /**
     * 添加财务支出信息
     * @param fiscalExpenditure
     * @return
     */
    @RequestMapping("insertFiscalExpenditure")
    public int insertFiscalExpenditure(FiscalExpenditure fiscalExpenditure){
        return fiscalExpenditureService.insertFiscalExpenditure(fiscalExpenditure);
    }

    /**
     * 根据主键ID进行删除财务支出信息
     * @param fExpenditureId
     * @return
     */
    @RequestMapping("deleteFiscalExpenditure")
    public int deleteFiscalExpenditure(String fExpenditureId){
        return fiscalExpenditureService.deleteFiscalExpenditure(fExpenditureId);
    }

    /**
     * 批量删除
     * @param fExpenditureId
     * @return
     */
    @RequestMapping("deleteFiscalExpenditureById")
    public int deleteFiscalExpenditureById(String fExpenditureId){
        return fiscalExpenditureService.deleteFiscalExpenditureById(fExpenditureId);
    }

    /**
     * 根据主键ID进行修改财务支出信息
     * @param fiscalExpenditure
     * @return
     */
    @RequestMapping("updateFiscalExpenditure")
    public int updateFiscalExpenditure(FiscalExpenditure fiscalExpenditure){
        return fiscalExpenditureService.updateFiscalExpenditure(fiscalExpenditure);
    }

}
